package org.bitterorange.flansmodslain.listeners;

import com.flansmod.common.eventhandlers.AmmoSupplyEvent;
import com.flansmod.common.eventhandlers.HealSupplyEvent;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import org.bitterorange.flansmodslain.models.BukkitAmmoSupplyEvent;
import org.bitterorange.flansmodslain.models.BukkitHealSupplyEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public class PlayerSupplyListener {

    @Mod.EventHandler
    @SubscribeEvent
    public void onAmmoSupply(AmmoSupplyEvent e) {
        Player supplier = Bukkit.getPlayer(e.getSupplierName());
        Player supplied = Bukkit.getPlayer(e.getSuppliedName());
        if (supplier != null && supplied != null) {
            Bukkit.getServer().getPluginManager().callEvent(new BukkitAmmoSupplyEvent(supplier, supplied, e.getClips()));
        }
    }


    @Mod.EventHandler
    @SubscribeEvent
    public void onHealSupply(HealSupplyEvent e) {
        Player supplier = Bukkit.getPlayer(e.getSupplierName());
        Player supplied = Bukkit.getPlayer(e.getSuppliedName());
        if (supplier != null && supplied != null) {
            Bukkit.getServer().getPluginManager().callEvent(new BukkitHealSupplyEvent(supplier, supplied, e.getHealAmount()));
        }
    }
}
